package net.borlis.rest;

import net.borlis.processor.api.object.AccountObject;
import net.borlis.processor.api.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;

import static org.springframework.web.bind.annotation.RequestMethod.*;

/**
 * Created by borlis on 24.12.2014.
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/create", method = PUT)
    public AccountObject create(
            @RequestParam(value = "userId") BigInteger userId,
            @RequestParam(value = "name") String name,
            @RequestParam(value = "surname") String surname,
            @RequestParam(value = "login") String login,
            @RequestParam(value = "password") String password) {
        return accountService.create(userId, name, surname, login, password);
    }

    @RequestMapping(value = "/read", method = GET)
    public AccountObject read(
            @RequestParam(value = "id") BigInteger id) {
        return accountService.read(id);
    }

    @RequestMapping(value = "/update", method = POST)
    public AccountObject update(
            @RequestParam(value = "id") BigInteger id,
            @RequestParam(value = "name") String name,
            @RequestParam(value = "surname") String surname,
            @RequestParam(value = "login") String login) {
        return accountService.update(id, name, surname, login);
    }

    @RequestMapping(value = "/delete", method = DELETE)
    public void delete(
            @RequestParam(value = "id") BigInteger id) {
        accountService.delete(id);
    }
}
